﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 生命体征测试仪
{
    public partial class formTimeRange : Form
    {
        public formTimeRange()
        {
            InitializeComponent();
            numKey1.NumKey_BtnClicked += new 生命体征测试仪.NumKey.BtnClickHandle(InputNum);
            numKey1.Set1("下一项");
        }
        public static DateTime t1,t2;
        void InputNum(int n)
        {
            
            this.Invoke((EventHandler)(delegate
            {
                if (n == -2)
                {
                    if (curIndex == 0)
                    {
                        curIndex = 1;
                        tbStart.BackColor = System.Drawing.Color.White;
                        tbEnd.BackColor = System.Drawing.Color.Gold;
                    }
                    else
                    {
                        curIndex = 0;
                        tbStart.BackColor = System.Drawing.Color.Gold;
                        tbEnd.BackColor = System.Drawing.Color.White;
                    }
                    return;
                }
                if (curIndex == 0)
                {
                    if (n == -1)
                        tbStart.Text = "";
                    else
                        tbStart.AppendText(n.ToString());
                }
                else
                {
                    if (n == -1)
                        tbEnd.Text = "";
                    else
                        tbEnd.AppendText(n.ToString());
                }
//                 if (n == -1)
//                     tbPhone.Text = "";
//                 else if (n == -2)
//                     tbPhone.Text = tbPhone.Text.Substring(0, tbPhone.Text.Length - 1);
//                 else
//                     tbPhone.AppendText(n.ToString());
            }));
        }
        int curIndex=0;
        private void skinButton2_Click(object sender, EventArgs e)
        {
            
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            try
            {
                t1 = DateTime.ParseExact(tbStart.Text, "yyyy年MM月dd日", null);
                t2 = DateTime.ParseExact(tbEnd.Text, "yyyy年MM月dd日", null);
            }
            catch// (System.Exception ex)
            {
                MessageBox.Show("您所输入的时间有误，请重新输入");
                return;
            }
            
            this.DialogResult = DialogResult.OK;
        }

        private void formTimeRange_Load(object sender, EventArgs e)
        {
            tbStart.BackColor = System.Drawing.Color.Gold;
            tbEnd.BackColor = System.Drawing.Color.White;
            if(t1.Year>2015)
                tbStart.Text = t1.ToString("yyyy年MM月dd日");
            if(t2.Year>2015)
                tbEnd.Text = t2.ToString("yyyy年MM月dd日");
        }

        private void tbStart_Click(object sender, EventArgs e)
        {
            curIndex = 0;
            tbStart.BackColor = System.Drawing.Color.Gold;
            tbEnd.BackColor = System.Drawing.Color.White;
        }

        private void tbEnd_Click(object sender, EventArgs e)
        {
            curIndex = 1;
            tbStart.BackColor = System.Drawing.Color.White;
            tbEnd.BackColor = System.Drawing.Color.Gold;
        }
    }
}
